// RobotInfo.cpp: implementation of the CRobotInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "yujinsrhost.h"
#include "RobotInfo.h"
#include "math.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRobotInfo::CRobotInfo()
{

}

CRobotInfo::~CRobotInfo()
{

}

/////////////////////////////////////////////////////////////////////
// Robot Draw 
// ID    : Robot ID Number 
// x     : Robot X Position	Resulution ,coordinate is Image Size 640 
// y     : Robot Y Position	Resulution ,coordinate is Image Size 480 
// Angle : Robot Angle 0 ~ 360
// pDC   : Graphic Device Context Pointer
//////////////////////////////////////////////////////////////////////

void CRobotInfo::DrawRobot(int x, int y, int Angle, int ID, CDC *pDC,BOOL OpOrMy)
{
	CPen pen,*oldpen;
	if(OpOrMy == TRUE) pen.CreatePen(PS_SOLID,1,RGB(0,0,127)); 
	else pen.CreatePen(PS_SOLID,1,RGB(0,255,0)); 
	oldpen = pDC->SelectObject(&pen);

	int RobotDrawPointX,RobotDrawPointY;
	int SizeXofRobot,SizeYofRobot;
	double s1,c1,s2,c2,idx1,idy1,idx2,idy2;
	//double 
	RobotDrawPointX=x;
	RobotDrawPointY=y;
	SizeXofRobot=40;
	SizeYofRobot=40;
	////////////////// edge for robot /////////////////////////
	
	s1=(SizeXofRobot/2)*sin(M_PI*((90-Angle)+45)/180);
	c1=(SizeYofRobot/2)*cos(M_PI*((90-Angle)+45)/180);
	s2=(SizeXofRobot/2)*sin(M_PI*((90-Angle)+135)/180);
	c2=(SizeYofRobot/2)*cos(M_PI*((90-Angle)+135)/180);
	
	//////// shape of robot patch //////////////////////////////
	idx1=((SizeXofRobot)/4)*sin(M_PI*((45-Angle))/180);
	idy1=((SizeYofRobot)/4)*cos(M_PI*((45-Angle))/180);
	idx2=((SizeXofRobot)/4)*sin(M_PI*((45-Angle)+90)/180);
	idy2=((SizeYofRobot)/4)*cos(M_PI*((45-Angle)+90)/180);

	//////////// draw edge ///////////////////
	pDC->MoveTo((int)(RobotDrawPointX+s1),(int)(RobotDrawPointY-c1)); 
	pDC->LineTo((int)(RobotDrawPointX+idx2),(int)(RobotDrawPointY-idy2)); 
	pDC->LineTo((int)(RobotDrawPointX+idx1),(int)(RobotDrawPointY-idy1)); 
	pDC->LineTo((int)(RobotDrawPointX-s2),(int)(RobotDrawPointY+c2));
	pDC->LineTo((int)(RobotDrawPointX-s1),(int)(RobotDrawPointY+c1)); 
	pDC->LineTo((int)(RobotDrawPointX+s2),(int)(RobotDrawPointY-c2));
	pDC->LineTo((int)(RobotDrawPointX+s1),(int)(RobotDrawPointY-c1)); 
	
	char tmp[10];
	CRect rect;
	int		oldBkMode;
	COLORREF	oldTextColor;
	rect.left = RobotDrawPointX-5;
	rect.right = RobotDrawPointX+5;
	rect.top = RobotDrawPointY-5;
	rect.bottom = RobotDrawPointY+5;

	sprintf(tmp,"%d",ID);

	oldTextColor	= pDC->SetTextColor(RGB(0,0,0));
	oldBkMode	    = pDC->SetBkMode(TRANSPARENT);

	pDC->DrawText(tmp,-1,&rect,DT_VCENTER | DT_CENTER | DT_NOCLIP | DT_SINGLELINE);
	pDC->SetTextColor(oldTextColor);
	pDC->SetBkMode(oldBkMode);

	pDC->SelectObject(oldpen);
	oldpen->DeleteObject();
	pen.DeleteObject();	
}

void CRobotInfo::EraesRobot(int x, int y, CDC *pDC)
{
	
}
